Session state lost in asp.net web farm - asp.net-mvc

I've been busy with this for months now.
I currently have 2 servers for 1 website. Using round robin dns I find that in the beginning everything works (checking the ip of the website it changed but I can go on with my session), but after a while I lose my session, seems like the formsauthentication cookie cannot be read and is being discarded. (assumption) But this does not happen all the time. Only sometimes.
I'm using iis7 shared configuration, I set the machine key and I'm using stateserver pointing to one of the servers and I verified that on both servers the stateserver works.
I read something about the IIS application path, but I don't really know what is meant by that, is it the path of the webapp, or the path where IIS is installed? In both cases they are the same.
Anyone have some ideas?

I'll answer this one myself, for anyone facing the same problem. Everything was set up correct but the machine key should be located in the web.config under system.web. Generating the key via iis 7 didn't work for some reason, I generated it with an online tool: http://aspnetresources.com/tools/machineKey
So, to do load balancing and set up multiple servers on iis7 you should:
Use a stateserver out-proc (stateserver or sql server) and have all
servers point to that stateserver (example: stateConnectionString="tcpip=server1:42424")
Use iis shared configuration so all your servers point to a share where the applicationhost.config resides.
Generate a machine key (not via iis, just use an online tool!)
Set up NLB (or round robin DNS) and test it by flushing your dns on
your client when you're logged in and see if your session doesn't get lost.
Hope this helps someone.

And the machine keys are specific to the .NET version. To check your current version: In the IIS console, at the server level, click "Change .NET Framework Version" in the Actions pane.

Related

Host website one webfolder down

I want my site to be hosted like this:
mysite.com/en/default.aspx
mysite.com/en-gb/default.aspx
mysite.com/de-ch/default.aspx
Originally I just hosted the site in application folders in IIS for each culture I support and everything was fine. I had a separate application in the root which forwarded the user to the appropriate culture. This was all grand.
However, now we're going to host with Azure and I need to get my site to fit into one web role (for those not familiar with Azure, just think of it as me only being able to host the website once - so no application folders). To this end, my site correctly collects the webfolder for the culture and sets the threading appropriately, all this is fine. My problem is that now as far as IIS is concerned the page 'default.aspx' does not exist in the folder 'en-gb'. That folder doesn't really exist. I need to get my site to ignore that first webfolder when it considers what content to get.
It's an interesting one, I suspect my solution lies in URL rewriting. Does anyone have any advice on this?
Thanks for the help!
Well I have found the answer.
It turns out that a web role is capable of much more. I understood that it was a web site running under a virtual machine, but that virtual machine could be torn down and moved at any point. However there is a facility to control what is going on in IIS on that virtual machine within your project. By editing your ServiceDefinition.csdef file you can add virtual applications and virtual directories. More details here:
http://www.dotnettwitter.com/2012/03/publishing-multiple-sites-sub-sites.html
I didn't need to use any fancy URL rewriting. I now have several sites running under one web role.
Well... I will do once I figure out what is stopping my main site working under Azure, but this question is answered.

How to publish and host a MVC4 application in your domain?

I have a webdomain www.MyDomain.com and a MVC4 web application MyMVCWebApp.
First I publish the application to a local destination.
For instance: C:\TempLocation
And then I host it to my domain with a FTP-tool (FileZilla??)
The files will be hosted but I can't find the webpage.
Which url do I have to write?
http://www.MyDomain.com/MyMVCWebApp/Home/Index.chtml or something?!
Do I have change the settings in my web.config?
What do I have to do?
You can't host an application on a domain.
An application is hosted on a web server. A domain name is only a way to translate an easy to remember address like "www.google.com" to the web server ip address which looks like 173.194.66.104
It is possible to purchase a domain without a web server.
So before going further:
Check if you actually bought a domain only, or a domain with a server
Your domain should redirect to your server ip address, you can see if he is correctly configured by opening a command prompt and doing
C:\> ping www.yourdomain.com
If this is not the case you will need to update the A record of your domain, and wait for the update to be replicated on DNS server worldwird.
If you have a managed server, you should check your hosting provider website. They usually provide in depth documentation, and they all have a different way to do things. Most of the time indeed you will be able to upload your files using a FTP software such as Filezilla.
However, in order to host a MVC 4 application you need a server with
the IIS web server, which means that you need a Windows server. So if
you have a Linux server, you should contact your hosting provider
support and tell them you made a mistake during your order. (It is
possible to host a MVC 4 application on Linux, but I don't think it
is often provided on managed servers)
If you have a dedicated server you are on your own.
The URL you will have to write to access your application will depends on what you have configured in the RegisterRoutes method of the RouteConfigs.cs file.
I recommend you to watch the last video on this page to have a better overview of the possibilities.

Why do I have unstable session in a MVC3 application with godaddy servers

I have a MCV3 application in godaddy serves and the session is quite unstable.
When I login it works fine but while navigating in the application it logs me out, and hitting refresh or navigating a little more inside the application in logs me in just like that (without asking credentials or anything). On my remote test servers and local in works fine.
This is probably not a session issue but rather an authentication cookie/ticket issue. GoDaddy (most likely) has their servers load balanced. Meaning that your application actually exists on more than one server at a time.
In your web.config, if you are not properly defining the <machineKey> attribute, then IIS makes up a machine key for you. Each server running the application will make their own machine key if it is not defined by you. As a result, one server is able to decrypt and read your authentication ticket, while the next request goes to another server which cannot decrypt the authentication ticket because it was encrypted with a different key and this server thinks that you are not logged in.
To address this issue, open your web.config file and define your <machineKey> attribute and redeploy. Once you login with the newly deployed application, you should see this issue disappear.
Forms authentication and Machine Key information on MSDN
Machine Key Generator (Most likely, everyone going here should use the .NET 2.0 version that is generated)

ServicePrincipleName setup for Web Service on IIS 7

I'm so confused.
Consider the following:
Active Directory environment with a domain called DOM
An IIS 7 box with a NetBIOS name VS1
A DNS record providing an alias for VS1 as pineapple.london.uk.corp
An Application Pool running as DOM\PineappleService
Windows Authentication enabled.
Clients use HttpWebRequest to call the XML/JSON ASP.NET services on the box.
The service calls out to workstations on the network to gather information. This works in development where I use IIS Express which runs as me, since IISX is just an .exe
In production, services work fine, authentication works, but invoking functions that cause the service (running as PineappleService) to access stuff on the network, fails.
I suspect an SPN registration issue but I don't know what SPNs to setup.
Most recently, I've stumbled across this article which seems to say fly in the face of some other articles:
http://blogs.msdn.com/b/webtopics/archive/2009/01/19/service-principal-name-spn-checklist-for-kerberos-authentication-with-iis-7-0.aspx
Note that it says
The SPN requirements remain the same as above. You don't have to add
SPNs like http/ for the Domain1\Username1
unlike in IIS 6.0 (where we had to add an SPN of the form
http/ for the Application Pool identity).
So I don't know what's right anymore. I don't know if I need to register HTTP SPNs or HOST SPNs or use the DNS alias or the NetBIOS name, and set them on the PineappleService account or on the VS1 computer account.
I can't tell if when I try things that there's a slow AD replication issue that means I must wait an hour between trial and error.
It's all so complicated now. I've worked as a sysop and dev for 15 years and I sense the end of domains and workstations and rights and policies. It's all gotten too much.
Thanks for your help.
Luke
This is a cross-post with ServerFault which is getting no answers:
https://serverfault.com/questions/417483/serviceprinciplename-setup-for-web-service-on-iis-

SharePoint Search with Network Load Balancing (NLB)

SharePoint MOSS 2007 on 64 bit OS and SQL. Added a new Web Front End to our farm, all sites seem to work fine - but now we've noticed that the search service has completely stopped working. It works if I change my host file to point to the original WFE, but if I use the NLB IP or the IP of the new WFE, it says "Unable to Connect to the Search Service.
Help.
As someone who was recently a sharepoint developer one of the biggest issues I have come across is load balanced environments. Does your alternate access mapping file contain the proper references?
The way we do it is to keep one WFE outside the NLB and have the indexer use that machine. Not only is this better for performance (the separate WFE serves the indexer only, regular traffic goes through the NLB. This way, indexing doesn't interfere with regular users visiting the site)
The other pro is that you circumvent issues like this.
P.S. This question DOES belong on serverfault though, voted to move..
I just setup a new medium farm MOSS 2007 x64 environment and ran into a few snags. This is what we ended up doing:
2 WFEs, 1 Index, 1 SQL - all running Windows 2008 Server
The 2 WFEs have an NLB cluster configured and host queries (but not indexing).
The Index is also a WFE, is NOT part of the cluster, hosts indexing (but not queries).
The Index had to have the loopbackcheck disabled and a hosts file entry setup to point the portal DNS name to 127.0.0.1. Without those settings it was generating errors. With these settings, it can index itself without affecting the portal performance while still being able to replicate its index to the query servers.
Hope that helps.

Resources