|
|
HI Vani,
Yes i want to use a global progress bar. So that i can use it in entire of my application.
And the above solution you gave is not working. When i give any request it is not even displaying. So Plz help me.
|
|
|
|
|
Hello,
I was wondering if anyone has any input or guidance in why some PS cmdlets won't work on remote computers when executing a script file from an ASP.NET site.
These scripts work from PS console on server1 to the Spooler service on server2 and also work if the script is run via ASP.NET on itself.
Invoke-Command -ComputerName "Server2" -scriptblock {Stop-Service -Name "Spooler" -Force}
However, through the ASP.NET site it doesn't work. There are no errors or any output that I can see.
I was able to get around this by using the -Credential switch. But this requires me to hard code the credentials which I do not want to do.
$username = Get-Content "C:\inetpub\wwwroot\Scripts\_un.txt"
$password = Get-Content "C:\inetpub\wwwroot\Scripts\_pw.txt"
$password = $password | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
Invoke-Command -ComputerName "Server2" -Credential $cred -scriptblock {gwmi win32_service -filter "Name='Spooler'" | Stop-Service -Force}
Invoke-Command -ComputerName "Server2" -Credential $cred -scriptblock {Stop-Service -Name "Spooler" -Force}
This is how I'm executing the PS scripts in ASP.NET C#.
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
var shell = PowerShell.Create();
string filePath = Server.MapPath("PS/StopSpooler.ps1");
StreamReader reader = File.OpenText(filePath);
string powerShellCode = reader.ReadToEnd();
reader.Close();
shell.Commands.AddScript(powerShellCode);
var results = shell.Invoke();
My site is very basic and is using Windows authentication. It is also being launched while logged in as a domain administrator.
Thanks!
modified 26-Jul-12 3:07am.
|
|
|
|
|
In a C# 2010 web application, I want to add a server side regular expression value that can edit a date in the following format:
mm/dd/yyyy where mm is month, dd is day, and yyyy is year. I want the user to be required to enter the backslashes. From what I have seen on the internet, the following 2 examples would have the code that works:
1. (0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d)
2 ^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](19|20)\d\d$
Based upon the above, can you tell me the following:
1. Which method would work and why?
2. If neither method would work what would you recommend that would work?
3. From the examples above, what does [- /.] stand for? I know the dot is only one character and the / is the character that is being looked for? However what does the dash followed by a space mean? Is this the same meaning as [/]?
4. In the above examples you can see 1[012]. Does that mean that the first digit must 1 and the second digit can be either 0 or 1 or 2?
5. When looking at the regular expressions, is there a way to tell what the pattern being matched against means? Basically is there a way to tell what the regular expression means by using a tool like the .net debugger?
|
|
|
|
|
dcof wrote: I want the user to be required to enter the backslashes. Firstly those are not backslashes and secondly why do you want such an unfriendly web page? Use a Calendar control[^] that does all the work for you.
One of these days I'm going to think of a really clever signature.
modified 26-Jul-12 6:21am.
|
|
|
|
|
The requirements from the user explicitly states that they can either use a calendar control or type in the date. So I am using a calendar control already. However they want to be able to enter the date manuallhy if they chose to.
Is there a way I can make them use a calendar control only?
|
|
|
|
|
Take a look at this article[^] for some suggestions.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi,
I have web page that has useful information on it but I don't want any user copy this information or add my logo if user copy this.please help me
|
|
|
|
|
You can't. You can make it complicated, but you cannot fully prevent a user from copying the contents.
|
|
|
|
|
So, how can I complicate it ? can I Add logo of my site in a back ground or some thing like this when they copy this data the logo appear on it?
|
|
|
|
|
It's impossible to prevent someone from taking a screenshot So if you embed your image as base64, split up the base64-string in variables and spread it around in a bunch of js-files, it's still easy to copy your logo.
--------------------
When Chuck Norris' dreams come true, your worst nightmares begin.
|
|
|
|
|
That's a good idea thanks but can you give me an example of it , write some code please
|
|
|
|
|
code to base64 encode and split it?
You can do it. I'll give you a few tips:
Online tool for converting images to base64 embedded image: http://webcodertools.com/imagetobase64converter/[^]
This will give you an img-tag ready to use.
Example (using jQuery):
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf89hAAAAB3RJTUUH2AQPB0tAAAAARnQU1" />
I removed most of the string for it to be easier to read. They are usually very long
Then you take the base64 value "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf89hAAAAB3RJTUUH2AQPB0tAAAAARnQU1", put it in a javascript variable (or multiple) like this:
var part1 = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAA';
var part2 = 'QCAYAAAAf89hAAAA';
var part3 = 'B3RJTUUH2AQPB0';
var part4 = 'tAAAAARnQU1';
Remove the src-attribute value from your img-tag and give it an id-attribute
<img src="" id="myImg"/>
$(document).ready(function(){
var base64src = 'data:image/png;base64,' + part1 + part2 + part3 +part4;
$('#myImg').attr('src', base64src);
});
This will NOT prevent a user from copying your image! It's (as I said) easy to do a screenshot...
--------------------
When Chuck Norris' dreams come true, your worst nightmares begin.
|
|
|
|
|
I did it but it doesn't different between your code and add image as background , I want when user copy my text in a web page and paste it on word both text and logo paste
|
|
|
|
|
Isn't your question about preventing this?
--------------------
When Chuck Norris' dreams come true, your worst nightmares begin.
|
|
|
|
|
Did you mean, you want the users to avoid following things
1) Dont save your page
2) avoid right click and ctrl+c
|
|
|
|
|
yes exactly, or if user copy my page also my logo paste on it
|
|
|
|
|
You can't do this I'm afraid. If the user turns off JavaScript, your page is purely the content and the user can copy it as they like.
|
|
|
|
|
Hi! I am making an e-shop and i have a search function where you can search for a product in the website. So, it returns the products on the search result page. Then, i want to be able to add the product to cart from the result page. For some reason, the same code i use elsewhere is not working.. i am getting the "Index was out of range. Must be non-negative and less than the size of the collection." error.
Here is my code:
Protected Sub DataList1_ItemCommand(sender As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
Dim currentCommand As String = e.CommandName
Dim currentRowIndex As Integer = Int32.Parse(e.Item.ItemIndex)
If currentCommand = "ProductID" Then
Session("Product") = DataList1.DataKeys(currentRowIndex)
Response.Redirect("Search.aspx", False)
ElseIf currentCommand = "AddtoCart" Then
Session("Product") = DataList1.DataKeys(currentRowIndex)
ShoppingCart.Instance.AddItem(Session("Product"))
Response.Redirect("ViewCart.aspx", False)
End If
End Sub
As you can see, i used the Label2 to check the value of the currentRowIndex. In the search i made i had 2 records, for the first one currentRowIndex=0 and for the second currentRowIndex=1.
What am i doing wrong?
|
|
|
|
|
That's pretty slick code there, and you even knew how to access data from the EventArgs. Strange if you know how to use the eventarg, that you didn't test the value of it e.Item.ItemIndex to make sure it's a value from 0 to the max value of int32.
I don't see the purpose of passing the session value to the shopping cart instance
Dim currentRowIndex As Integer = Convert.ToInt32(e.Item.ItemIndex)
Session("Product") = DataList1.DataKeys(currentRowIndex)
ShoppingCart.Instance.AddItem(DataList1.DataKeys(currentRowIndex))
|
|
|
|
|
Such an error can be thrown when you do DataList1.DataKeys(currentRowIndex) .
For debugging purposes, I'd add some lines after Dim currentRowIndex ... for checking that value:
If currentRowIndex<0 Then
ElseIf currentRowIndex>=DataList1.DataKeys.Count Then
EndIf
You should show the value of currentRowIndex and DataList1.DataKeys.Count in the error messages, and then do some further analysis based on those values.
|
|
|
|
|
I should of wrote
If Not currentRowIndex > Integer.MinValue And currentRowIndex < Integer.MaxValue Then
'Deal with the Error
Else
'now run the code
End If
|
|
|
|
|
Thank you so much guys! I solved the problem
Actually it was something stupid in the asp code.. i forgot to use DataKey field so, of course, DataList1.DataKeys.Count was always = 0 :P
|
|
|
|
|
Good to hear,
you should still improve the code you posted to better handle and invalid input, it will bite you back in the future,
In the future, you will start checking the error logs on your web server, and you will see all these errors, from input that was not validated. I see bots pick up trying to break a website all the time.
|
|
|
|
|
I added the code you suggested. But unfortunately i don't know a lot about security yet, for now i'm trying to fix the basics. I guess in 2-3 weeks you will see my posts here asking about security issues
|
|
|
|