Unable to read cookies - c#

I am currently using a WSS 3.0 Web Part (C#) for creating a cookie.
I have a link button in my Sharepoint site which has an event that calls an encryption method and then stores the encrypted value in the Cookie. After creating the cookie, I am redirecting the user to a new URL which opens in a new window.
The cookie creation is successful. I was able to store my desired value and the domain that it gets is the one of where the link button is located.
What I want to do is to open the cookie in the newly opened window but when I try to use HttpContext.Current.Request.Cookies["cookieName"] I always get a null.
Can anyone help me with this issue ? I've been working on this for a couple of days now. I believe that there is an issue here regarding domains but I can't figure out the right solution.

I would start troubleshooting this by using browser developer tools (e.g. F12 in IE) to ensure that the cookies are actually being saved on the client - yes? Then :-
Is the new window opening with a URL that has a domain the same as the orig URL?
e.g.
#1 http://site.yourdomain.com/page1
#2 http://site.yourdomain.com/page2
If not then site1 can't read site2's cookies.
You also need to do some extra stuff to share across sub-domains.
MSDN - ASP.NET Cookies Overview

Related

C#.net / MVC4 Authorize.net ARB - Subscription needed to register for an account

I am making my first subscription based website in MVC4 / C# / Razor and have created an Authorize.net "Card Not Present" sandbox account for testing.
I have implemented the subscription and it works like a charm. I am redirecting the new subscriber to the "Registration" page using the built in Visual Studio 2013 site that is created by default.
I have saved the SubscriptionId that was returned from Authorize.net and put it into a session variable. I then look at that session on the Registration page to see if it has a value or not.
If there is a value then I allow the user to create an account, otherwise I redirect them to an error page.
Is there anything you think I should add / best practices? I also planned on storing the SubscriptionId with the account when it gets created so I have a way to link up the user to a subscription on Auth.net's website.
Second question: Is there a way to ping Auth.net every time a user logs in so I can check to see if they still have an Active subscription? I would imagine that storing the SubscriptionId would be helpful so that is why I am saving it. I checked the documentation from Authorize.net and didn't see anything... I want to make sure people aren't getting a free ride out of the site...
Thanks in advance for your help / suggestions...
For your second question, if you've stored the subscriptionId in your database, you can use ARBGetSubscriptionStatusRequest to determine if they have an active subscription.
http://developer.authorize.net/api/reference/#recurring-billing-get-subscription-status

Browser is not reading the response cookie

I am creating a cookie with a value(like an Id) and adding it to the browser's response context.
So when the www.abc.com is called from my applciation through click, it auto logs into abc.com web site.
When I log out of abc.com without closing the window(www.abc.com) and try to click the link from my application again, it is creating a new cookie with a new value but it is not auto login to www.abc.com
But when I logout from www.abc.com and close the window(www.abc.com) and reclick from my application, it let me autologin.
Any ideas?
Telepathic powers: you are deleting cookie from wrong domain (setting cookie on abc.com, but deleting only from www.abc.com).
Make sure that domain for both set and expire cookie calls is the same (either both calls made to/from page on abc.com domain OR domain is set correctly).
#Alexis: Thanks for pointing it out. But I did find the answer. The session was already open from the previous web site. As that wasn't closed, the new web site which got open when I clicked the link again couldn't establish a brand new session. SO the browser couldn't read the session cookie.That is why you always has to close the first one.
But thanks for helping me alexis. But I will remember to add more data in my question from next time onwards.

How to do Auto authentication for automatically login to website?

I need to get automatically login to website from my windows application. I am doing it with HttpWebRequest but what i want is to
Click on the button in my application.
Open the Index page (page after getting login)
Reason : I don't want to enter user name and pasword, i just want to click button and any browser(default browser) open with index page (page after login)
Normal Example :
I open a link " http://mail.yahoo.com " it shows me a page asking my email address and
password.
I enter the email id and password and press Login.
It redirects me to my Mail box page.
What to Do ?
click on the button
Automatically send my email id or user name and password to the website
Open my Mail box page.
Hint :
get cookie from HttpWebRequest.
set it to the browser.
Open browser and pass the credentials to login automatcially
can anyone help me?
I also need to solve the same issue, and the problem is hint point 2 in your list.
ie. how to set a cookie in a browser, without limiting yourself to using a specific broswer.
The conclusion I am coming to, is that I need to use a standard 'Single Sign-On' logic, where we update the web-server to use short term tokens such as mentioned here...
http://msdn.microsoft.com/en-us/library/ms972971.aspx
In this case the steps would be something like:
1. In app - Logon with HttpWebRequest.
2. Get short-term token (the link suggests validity lifetime of just 2 seconds)
3. Open browser with url
http://MyWebsite>/SignNn?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
4. Next I need to confirm if the SignOn process can return cookies correctly.
I dont think you can solve this in a generic way.
What usually happens in such scenarios is that the form within the web page is submited to web server, the web server reads the user name / password values from the form and authenticates the user against the underlying user managment repository.
You can write such a solution for specific sites, by analzying with a sniffer the posted form in the authentication pages, and then creating such an http message yourself and sending it to the relevant site.

Publish content to Facebook

I apologize if this has already been answered, but all the information out there on Facebook publishing is so confusing and conflicting, I haven't been able to get anything to work yet. I'm trying to set up an application that runs on my local server to publish content to my organization's fan page (this will tie in with my WCMS to cross-post content). I believe I want a Facebook Connect application to do this which I've set up properly in Facebook and gotten an application key and secret. Here's the code I'm trying to execute, but each time it's run I get "User has not authorized access" even if I'm just trying to publish to the application wall.
ConnectSession fbSession = new ConnectSession("APP_KEY", "APP_SECRET");
Api fbAPI = new Api(fbSession);
fbAPI.Stream.Publish("hello world");
I've also tried:
fbAPI.Stream.Publish("hello world", null, null, FAN_PAGE_ID, APP_ID);
I've granted my application access to publish on the fan page.
EDIT:
I've tried turning this into a Desktop application instead because it appears as though Javascript needs to be involved in order for it to be a Connect application. Here's the updated session initialization line. This now gives me a "Incorrect signature error."
DesktopSession fbSession = new DesktopSession("APP_KEY", false);
There is a similar question titled "How can I post to a facebook wall from a c# web service?" for which I provided a very lengthy answer, specifically indicating how to post to a page.
casperOne's solution works, however, I found this article to be the best solution.
http://tech.karolzielinski.com/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api
This authorizes the application to post directly to the Fan Page without having to go through an admin account.

Forms Authentication Redirect cause Anchor loss

So here is the problem.
I use Anchors as a non-refreshing way to allow bookmarking of currently view objects.
http://myserver/showobject.aspx#objectid=10
I use this so when updating the object id it doesn't try to do a refresh on the page.
Heres the rub.
I am using forms Authentication to handle access to these pages. So When you try to browse to the above link without having logged in first, it redirects you to the login page. Once you have been successfully authenticated it FormsAuthentication.RedirectFromLoginPage(...) you to the page you came from.
Except that it trunks the #objectid=10 bit off.
I have thought up a few hacks (set a cookie before the redirect to the login page and then read the cookie and update the link after the "RedirectFromLoginPage" is done) for getting around this, but was wondering if there was any real way to make FormsAuthentication.RedirectFromLoginPage do what i actually want it to do.
So recap:
Trying to goto
http://myserver/showobject.aspx#objectId=10
Redirected to login
Current/Wrong Behavior: redirected after login to
http://myserver/showobject.aspx -
sans #objectId=10
Future/Right Behavior: redirected after login to complete original url, http://myserver/showobject.aspx#objectId=10
Thanks for the assist in advance,
John.
temporary cookie is the way to go here. web browsers don't send anything after the "#" when telling the server which URL they are being referred from - so the server can't capture that info and know to use it after the user signs in
That part of the URL is called a fragment and doesn't get seen by the server side. There are hacky ways around it using an interstitial page and a bit of javascript, but it can get messy.
Could the problem be the pound sign instead of the question mark in your querystring?
I use forms authentication and never have any problems when using
page.aspx?value=x

Categories