Access IIS Websites Properties Using ServerManager - c#

I am able to display the sites in my IIS using the serverManager.Site. Is there any way to list the files in each of the Website. I need to change RequireSSL property of one of the File. Is that Possible using ServerManager? Or any other way to do the same like appcmd ? Any Help is appreciated.

I found a Solution in the link provided by Antonio in the comment. Basically we can change the ApplicationHost Config File to get it done. Heres the link again
Configure SSL on a Microsoft.Web.Administration.Application object?

Related

C# .Net Core get current website Microsoft.Web.Administration.Configuration

I need to get Microsoft.Web.Administration.Configuration object for the current website. Actually, I want to modify the existing settings in web.config but its bit difficult using .net-core I guess. At least if I know the site name then I can get the physical path and modify the web.config using XML API. Can anyone know how to get current website name that my code is running?
I saw Asp.net framework provides
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
method.
It will get the current website configurations. I am looking similar kind of API in .net-core.
I found the solution for this issue.
I have to use IHostingEnvironment.ContentRootPath to get the root directory path. Then change the web.config last modified date and time to current time.

Change xmlSerializer tempFilesLocation for a wcf client

We use WCF client in our project which is an Azure functions app, to communicate with an external web service. We need to change the xmlSerializer's tempFilesLocation because of the permission issue. I searched online and found the following configuration that we can use in our web.config which will solve the problem.
<system.xml.serialization>
<xmlSerializer tempFilesLocation="an absolute path of your choice"/>
</system.xml.serialization>
But in Azure Functions app, we don't have access to web.config, so we need to find a way to do it in the code. Is there any way to change tempFilesLocation in the code?
It's not possible to modify the web.config for functions running on the dynamic sku (where you pay-per-invocation).
However, if you create your function on the non-dynamic/classic sku (where you pay per vm, the pricing model for regular web apps) then you can modify the web.config settings via an applicationHost.xdt file. More details on how to work with xdt file here: https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples

Create asp.net website with editable config file

I want to create setup of my web application with editable web.config file content.
Any help?
If you are trying to change the config with your code, the following should help. Any time you execute the following code, your site will be restarted. So keep that in mind.
var config = (Configuration)WebConfigurationManager.OpenWebConfiguration("~");
var configSection = (MySectionTypeHere)myConfiguration.GetSection("system.web/section");
//make your edits here
myConfiguration.Save();
If this is not what you're looking for, perhaps you could provide some more information.
You could use a tool like MS Web deploy. Read more about it here. http://learn.iis.net/page.aspx/578/package-an-application-for-the-windows-web-application-gallery/

disabling mod-security cpanel

I developed a Sync. software based-on C#.
it read some values from database and make a string as url.
then call a url with WebClient and pass url with values.
at the server,i wrote a php page that use $_GET to fetching the values,then insert them to
mysql database...
for first record,that's work,but after that my program ends with 406-Not Acceptable exception.
after some searches i know the modsecurity in the problem.and i try to disable that.
so,i add these line to .htaccess file:
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
SecFilterInheritance Off
</IfModule>
but it doesn't work...
i try to solve that and i was found my cpanel is cpanel accelerated2...
so i change code to :
<IfModule mod_security2.c>
SecFilterEngine Off
SecFilterScanPOST Off
SecFilterInheritance Off
</IfModule>
but now,with this change,all of my pages doesn't work and i get error 500...
and now i like some one help me...
The directives you are trying to use won't work in a .htaccess file, they need to be added to the VirtualHost definition for the site you want mod security disabled for and the best way to do that with cPanel is to use a separate include file.
You can edit httpd.conf directly to add the include file and then update the changes with the cPanel httpd.conf distiller /usr/local/cpanel/bin/apache_conf_distiller --update . If you don't have root level access to your server your host should be able to do this for you.

Is it possible that Request.ServerVariables["HTTP_HOST"].ToString() can return a different host than what I see in the url bar

Say I have a remote page accessed through http://www.mypage.com/test.aspx. On that page I use the code Request.ServerVariables["HTTP_HOST"].ToString(). Is it possible that when I access the page the code can return a different url than that which I see in the url bar which is http://www.mypage.com/test.aspx? Any help would be appreciated. Thanks.
You could see any name that IIS has bound to your web instance. So, if your server is called "server1" and the IP address is 123.123.123.123 and all three of those are bound to your instance of IIS, you could see any of those values.
To look up what names are bound, open "Internet Information Services (IIS) Manager" (start, Administration tools), expand the tree till you see your sites. Find the one you are using. Right-click and choose "Bindings". Edit each of the bindings in the list. If they all say [IP address:] "All Unassigned", then your HTTP_HOST could be 1. the WWW address that you have configured via DNS, 2. the machine name 3. the IP address(es).
try to use:
HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
i hope that this will be work.
I was also facing the issue with HttpContext.Current.Request.ServerVariables["HTTP_HOST"] and figured it out. The best way to retrieve the hostname is "HttpContext.Current.Request.Url.Host". It resovled my issue.
Thanks,
Raj
It is possible, yes. A isapi_rewrite module could modify the value of HTTP_HOST before your own code is able to inspect it.
Someone has already mentioned local rewriters (isapi_rewrite), but there are also remote ones, like an ISA Server publishing your server. It's a configuration thingie to send original host headers (what the client entered), or the ones entered in the publishing settings.

Categories

Resources