SeviceStack Razor with SqlMembershipProvider authorization - razor

Razor is nicely working under it's own api url
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
</location>
but when SqlMembershipProvider authorization is added like so
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
The api/urls are redirected to the regular web forms login page as expected but never successfully redirects back after a correct user/pass is entered. The same login page works fine with the legacy .net .aspx locations in the app.
How do I configure SqlMembershipProvider to be run before my .cshtml pages so the User identity can be accessed via RequestContext.HttpContext.User as described in other articles?

Related

Redirect using web.config file when there is no pathname

I've been working on a ASP.NET web application project in Visual Studio. In that project, when the user enters the hostname they get a 404 error but what I would like to happen is for them to be redirected to the index.html when they have just entered the hostname.
Below is the code that I tried using but it didn't work. It said there were too many redirects which I think has something to do with the path value being empty
<location path="">
<system.webServer>
<httpRedirect enabled="true" destination="index.html" httpResponseStatus="Permanent" />
</system.webServer>
</location>
Does anyone have an suggestions?
If you are using MVC you could create a default route but since you asked for a way to do it in web.config try:
<configuration>
<system.web>
<customErrors defaultRedirect="index.html" mode="On">
<error statusCode="404" redirect="index.html"/>
</customErrors>
</system.web>
</configuration>

http redirect loop using location in web.config

I have a website inside which I have a directory I want to keep private. My login page is inside this directory called admin.aspx.
In my main Web.Config I have the following block:
<authentication mode="Forms">
<forms loginUrl="~/Account/admin.aspx" name=".ASPXFORMSAUTH"></forms>
</authentication>
And then in my subdirectory I have a second web.config file with the following:
<location path="admin.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
However when I try to get to admin.aspx I get this error:
The web page at http://localhost:51167/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252FAccount%25252525252525252525252525252525252Fadmin%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252fAccount%2525252525252525252525252525252525252fadmin has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
I don't understand why it's got itself in a loop. If I change web.config (inside the directory) to simply say:
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
I can get to it so is it something with the location option?
Thanks.

ASP.NET Razor Site: "This type of page is not served"

I've created an empty ASP.NET website (i.e. razor web pages) but I'm unable to reach the index.cshtml page.
This is true whether I have 'index.cshtml' in the URL or not.
The error pages says:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because
it has been explicitly forbidden. The extension '.cshtml' may be
incorrect. Please review the URL below and make sure that it is
spelled correctly.
Requested URL: /index.cshtml
Here is the entire contents of the web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="webpages:Enabled" value="true"/>
<add key="webpages:Version" value="3.0.0.0"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5" enableVersionHeader="false" requestValidationMode="2.0"/>
<pages validateRequest="false"/>
</system.web>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
<fileExtensions>
<remove fileExtension=".cshtml"/>
<add fileExtension=".cshtml" allowed="true"/>
</fileExtensions>
</requestFiltering>
</security>
<defaultDocument>
<files>
<remove value="index.cshtml"/>
<add value="index.cshtml"/>
</files>
</defaultDocument>
</system.webServer>
</configuration>
Can anyone tell me what I'm missing (or what I've added and which shouldn't be there)?

Report Viewer Web Control Version 10 Gives Error Despite Set Up Correctly

Reports are deployed and working, verified in Report Manager.
My application is an MVC2 app with my report on its own aspx page. This page worked with version 8 of the report viewer control, but we moved to new servers, upgraded sql server, and are trying to update our website to match.
The servers are Windows Server 2008 with IIS 7.5.
I am testing in both chrome and IE 9.
Despite my best efforts, I still get this error:
Report Viewer Configuration Error
The Report Viewer Web Control HTTP Handler has not been registered in
the application's web.config file. Add <add verb="*"
path="Reserved.ReportViewerWebControl.axd" type =
"Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" /> to the system.web/httpHandlers
section of the web.config file, or add <add
name="ReportViewerWebControlHandler" preCondition="integratedMode"
verb="*" path="Reserved.ReportViewerWebControl.axd"
type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" /> to the system.webServer/handlers
section for Internet Information Services 7 or later.
But, I've already done this. in fact, I even read this from MSDN:
To use IIS 7.0 in Integrated mode, you must remove the HTTP handler in system.web/httpHandlers. Otherwise, IIS will not run the application, but will display an error message instead.
Just to be safe, I tried a combo of neither while adding the handler into IIS directly, just the web server http handler in my config, just the http handler in my config, and both.
Let's start with my web.config
<configuration
<system.web>
<httpRuntime maxQueryStringLength="4096" />
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>
</compilation>
</system.web>
<system.webServer>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
</configuration>
I have the assemblies, the build provider, and the handler. What else could be wrong?
I found a quick and dirty workaround - to your web config add this:
<location path="Reserved.ReportViewerWebControl.axd">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
I saw in fiddler that for some reason when page requested Reserved.ReportViewerWebControl.axd instead of getting HTTP 200 response server would send 302 - moved to login.aspx?returnurl="Reserved.ReportViewerWebControl.axd. So allowing all users to the handler path solves the problem.
I thought its ReportViewer Rendering Issue on IIS7
I have manually mapped my reportviewer handle to IIS7 like this:
•Open Internet Information Services (IIS) Manager and select your Web application.
•Under IIS area, double-click on Handler Mappings icon.
•At the Action pane on your right, click on Add Managed Handler.
•At the Add Managed Handler dialog, enter the following:
Request path: Reserved.ReportViewerWebControl.axd
Type: Microsoft.Reporting.WebForms.HttpHandler
Name: Reserved-ReportViewerWebControl-axd
•Click OK.
also changed by web config by adding
Still mine's not working. I thought the above solution would help others.
I have tries this by removing unwanted mvc assemblies from asp.net project. So the simple solution was to remove WebMatrix.*.dll from Bin folder in web project as that belongs to mvc framework.

Allowing access to my Site.Css on my login form MVC

I need my css to show for my login page, but it's not showing at the moment. How would I go about allowing access to my login page with the css included? Im using forms authentication, and my code block for my web.config file looks as such:
<authentication mode="Forms">
<forms loginUrl="UserAccount/Login" defaultUrl="UserAccount/Index" timeout="60"></forms>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
My site.css is in my /Content/Site.css path. How do I add it to allow access to this file to all users?
the <deny users="?"/> denies anonymous users from accessing the css file. (read here)
so you'll need to put the following into your <configuration> block within web.config
<location path="Content">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
you can read some more about this here
I work this out by the followings steps:
IIS Manager
Authentication
Right Click Anonymous Authentication.
Switch to application pool identity
Stumbled across this, cause I needed the same thing. Here is a solution:
<location path="Content">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
As is writer here (I used the link from the previous answer) this will give the unauthenticated user access to all the files in the Content folder, and the css file is in this folder.
P.S. sorry guys, this is the same as the previous answer, just ignore this