New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using "RequireHttpsAttribute" on a global level in Asp.net 5 #895
Comments
Filters only apply to MVC, you need to write a piece of middleware that does the same thing as the filter. |
Can't we make changes to a |
I don't see how web.config helps |
You can set a rule for IIS to redirect requests for HTTPS that way. |
|
Perfect, you don't even need the MVC filter 😄 Just that you; tied to IIS which might be fine for @Sharpiro |
The solution @guardrex posted was actually what i was currently doing. It was just a bit tedious having to paste that code snippet into the azure web.config after every publish from VS. But i actually took @davidfowl 's advice and created some middleware that just forces the redirect. Thanks. |
What I was trying to say was that you can put that into a |
I see, that is a good idea. However, one of the new features i enjoy about asp.net 5 is the lack of a web.config as needed in my project. Thanks for your help. |
@Sharpiro Would you be opposed to sharing the middleware bit you created? I'd like to see and possibly use that ... esp for a non-IIS project at some point. |
https://github.com/Sharpiro/ASP5_Template/tree/master/src/ASP5_Template_Web/Middleware Here's a link to the project i've been working on. I'm pretty new to Owin so it took me a bit to get all the pieces working. But now that it works it looks pretty simple. This was just a quick implementation so my logic for moving from "http" to "https" is simplistic and only works in a deployed IIS/Azure environment where port number differences do not matter. |
Oh, yes. Indeed. I like that. Very simple ... very effective. I think that will work anywhere. Thanks for sharing. 🍺 |
GetDisplayUrl is the wrong one to use. |
Ok, I changed it to: "context.Request.GetEncodedUrl()" if that's what you're referring to. |
Yes, if you read the doc comments: GetEncodedUrl
GetDisplayUrl
|
Thanks for sharing. |
I want to declare in code that I want to require the use of HTTPS.
In the past, I used this in Global.asax.cs:
I'm currently using this in "ConfigureServices" method of "Startup.cs":
While this works for all of my API calls, it doesn't do anything for my static files and default files which are initialized like so in "Startup.cs":
I'm currently having to go into Azure after each publish and modify the created web.config (since I don't use it in asp.net 5) and forcing the redirect to HTTPS there.
Is there a way to globally declare the "RequireHttpsAttribute" similar to how it was done in the past? If not, should this be implemented somehow?
Thanks.
The text was updated successfully, but these errors were encountered: