3

I am using Asp.net MVC 5 on Azure websites and SQL Azure.

I have specified 2016 in the question, as I am aware of many outdated approaches.

How can I setup the SQL Azure schema? Trying to locate the script files.

Am I mistaken in using this mode, or should I be using Redis or Table Storage. Redis is obviously quite expensive, around £65 per month for cheapest 99.9% SLA option.

Thanks.

EDIT 1

It looks like MS no longer supports session management in SQL Azure, see: MS Article

As far as I understand they recommend only using Azure Redis caching. Am I correct? I am very surprised one cannot use SQL Azure. I know it may be a little slower, but it would be straightforward and reliable.

1 Answer 1

3

Yes you should use Azure Redis. I'm not sure why sql would be more straightforward than using Redis. Using Redis is as simple as pulling in the nuget project and making the addition to the web.config to configure the session state provider as your azure Redis instance you have created. From there you can start using the Redis libraries.

 <sessionState mode="Custom" customProvider="RedisSessionProvider">
  <providers>
    <add name="RedisSessionProvider" 
         type="Microsoft.Web.Redis.RedisSessionStateProvider" 
         port="6380" 
         host="YOURCACHE.cache.windows.net"
         accessKey="Primary Access Key" ssl="true" />
  </providers>
</sessionState>

public class HomeController : Controller
{
    public ActionResult Index()
    {
        object value = Session["Home"];
        int result = 0;
        if (value != null)
        {
            result = (int)value;
            Session["Home"] = ++result;
        }
        else
        {
            Session["Home"] = 1;
        }

        return View();
    }

    public ActionResult About()
    {
        object value = Session["Home"];
        string home = "Didn't work";
        if(value != null)
        {
            home = ((int)value).ToString();
        }
        ViewBag.Message = string.Format("The cache value is {0}", home);

        return View();
    }
}

Here's a link on how.

Sign up to request clarification or add additional context in comments.

10 Comments

Thank you for this. I am testing this out. However any ideas how to setup SQL Azure as the session provider. The install scripts seemed to have disappeared. Is using SQL Azure a big no, no?
Interestingly I have had no end of issues trying to create an Azure Redis Cache. I keep getting ServerTimeOut errors. I have tried on the Northern Europe and Western Europe Data centre. Seems to take a long time, then fail. How long should creating a Redis Cache take?
Our Redis deployments did work in the end, just took a long time, around an hour.
The link above talks above about Session.Add, but even with the addition of "using StackExchange.Redis;", I still get a "Name session does not exist in current context. Basically it cannot find "Session".
While studying for my Developing Azure solutions certification the documentation always read to use Redis for session management and didn't indicate another path was supported. They may no longer support using Azure sql for session management which could be why it's so hard to find documentation on it. I certainly haven't been able to find any.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.