Reputation: 1
Not allow user to access HTML file only authenticated user can access HTML file. I have already put authentication in web.config file but this is not working.
<location path="test">
<system.web>
<authorization>
<allow users="?"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
when I put this code in my Web.config file it's only unauthenticated user to access HTML files. when I am authenticated to application to login it's not access to HTML file.
This code is only deny to access not allow to access "test" folder for authenticated user.
Thanks in advance !!!
Upvotes: 0
Views: 792
Reputation: 657
Well i have a way to do it with httphandlers.
First add a class to your project and implement the IHttpHandler class. Then
add this sample code to the ProcessRequest
method.
if (!HttpContext.Current.User.Identity.IsAuthenticated )
{
HttpContext.Current.Response.Write("//No authenticated access to static files are allowed");
return;
}
var requestedFile=File.ReadAllText(HttpContext.Current.Request.PhysicalPath);
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Write(requestedFile);
Of course don't forget to add this reference to the web config.
<add verb="*" path="*.html" type="YourNamespace.YourClassName, YourNameSpace" name="JS" />
Hope it helps.
Upvotes: 1