June 26, 2015 08:08 by
Peter
Today, let me explain about how to Authenticate HTML files with ASP.NET MVC. To Check Html URL is Authenticated or Not Using Asp.net/MVC using the following code:
Coding:
if (Request.RawUrl.ToLower().EndsWith(".html"))
{
if (Request.Cookies[".ASPXAUTH"] != null)
{
string value = Request.Cookies[".ASPXAUTH"].Value;
if (value == null || value == "")
{
Response.Redirect("~/Account/LogOn");
}
}
else
{
Response.Redirect("~/Account/LogOn");
}
}
The .ASPXAUTH is the Form Authentication Cookies and Account is the Controller. The LogOn is the action. Next step, write the following code in webconfig section:
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
<add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
<handlers>
<add name="HTML" path="*.html" verb="GET, HEAD, POST, DEBUG" type="System.Web.UI.PageHandlerFactory" resourceT
ype="Unspecified" requireAccess="Script" />
<add name="HTM" path="*.htm" verb="GET, HEAD, POST, DEBUG" type="System.Web.UI.PageHandlerFactory" resourceTyp
e="Unspecified" requireAccess="Script" />
</handlers>
I hope it works for you! Happy coding.
HostForLIFE.eu ASP.NET MVC 6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.